package cn.edu.scau.cmi.hombio.web.rest;

import cn.edu.scau.cmi.hombio.dao.CureTaskMedicineDAO;
import cn.edu.scau.cmi.hombio.dao.CureTaskMethodDAO;
import cn.edu.scau.cmi.hombio.dao.MedicineDAO;
import cn.edu.scau.cmi.hombio.dao.UnitDAO;

import cn.edu.scau.cmi.hombio.domain.CureTaskMedicine;
import cn.edu.scau.cmi.hombio.domain.CureTaskMethod;
import cn.edu.scau.cmi.hombio.domain.Medicine;
import cn.edu.scau.cmi.hombio.domain.Unit;

import cn.edu.scau.cmi.hombio.service.CureTaskMedicineService;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.WebDataBinder;

import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Spring Rest controller that handles CRUD requests for CureTaskMedicine entities
 * 
 */

@Controller("CureTaskMedicineRestController")

public class CureTaskMedicineRestController {

	/**
	 * DAO injected by Spring that manages CureTaskMedicine entities
	 * 
	 */
	@Autowired
	private CureTaskMedicineDAO cureTaskMedicineDAO;

	/**
	 * DAO injected by Spring that manages CureTaskMethod entities
	 * 
	 */
	@Autowired
	private CureTaskMethodDAO cureTaskMethodDAO;

	/**
	 * DAO injected by Spring that manages Medicine entities
	 * 
	 */
	@Autowired
	private MedicineDAO medicineDAO;

	/**
	 * DAO injected by Spring that manages Unit entities
	 * 
	 */
	@Autowired
	private UnitDAO unitDAO;

	/**
	 * Service injected by Spring that provides CRUD operations for CureTaskMedicine entities
	 * 
	 */
	@Autowired
	private CureTaskMedicineService cureTaskMedicineService;

	/**
	 * Save an existing Medicine entity
	 * 
	 */
	@RequestMapping(value = "/CureTaskMedicine/{curetaskmedicine_id}/medicine", method = RequestMethod.PUT)
	@ResponseBody
	public Medicine saveCureTaskMedicineMedicine(@PathVariable Integer curetaskmedicine_id, @RequestBody Medicine medicine) {
		cureTaskMedicineService.saveCureTaskMedicineMedicine(curetaskmedicine_id, medicine);
		return medicineDAO.findMedicineByPrimaryKey(medicine.getId());
	}

	/**
	* Save an existing CureTaskMethod entity
	* 
	*/
	@RequestMapping(value = "/CureTaskMedicine/{curetaskmedicine_id}/cureTaskMethod", method = RequestMethod.PUT)
	@ResponseBody
	public CureTaskMethod saveCureTaskMedicineCureTaskMethod(@PathVariable Integer curetaskmedicine_id, @RequestBody CureTaskMethod curetaskmethod) {
		cureTaskMedicineService.saveCureTaskMedicineCureTaskMethod(curetaskmedicine_id, curetaskmethod);
		return cureTaskMethodDAO.findCureTaskMethodByPrimaryKey(curetaskmethod.getId());
	}

	/**
	* Create a new Medicine entity
	* 
	*/
	@RequestMapping(value = "/CureTaskMedicine/{curetaskmedicine_id}/medicine", method = RequestMethod.POST)
	@ResponseBody
	public Medicine newCureTaskMedicineMedicine(@PathVariable Integer curetaskmedicine_id, @RequestBody Medicine medicine) {
		cureTaskMedicineService.saveCureTaskMedicineMedicine(curetaskmedicine_id, medicine);
		return medicineDAO.findMedicineByPrimaryKey(medicine.getId());
	}

	/**
	* View an existing Unit entity
	* 
	*/
	@RequestMapping(value = "/CureTaskMedicine/{curetaskmedicine_id}/unit/{unit_id}", method = RequestMethod.GET)
	@ResponseBody
	public Unit loadCureTaskMedicineUnit(@PathVariable Integer curetaskmedicine_id, @PathVariable Integer related_unit_id) {
		Unit unit = unitDAO.findUnitByPrimaryKey(related_unit_id, -1, -1);

		return unit;
	}

	/**
	* View an existing CureTaskMethod entity
	* 
	*/
	@RequestMapping(value = "/CureTaskMedicine/{curetaskmedicine_id}/cureTaskMethod/{curetaskmethod_id}", method = RequestMethod.GET)
	@ResponseBody
	public CureTaskMethod loadCureTaskMedicineCureTaskMethod(@PathVariable Integer curetaskmedicine_id, @PathVariable Integer related_curetaskmethod_id) {
		CureTaskMethod curetaskmethod = cureTaskMethodDAO.findCureTaskMethodByPrimaryKey(related_curetaskmethod_id, -1, -1);

		return curetaskmethod;
	}

	/**
	* Register custom, context-specific property editors
	* 
	*/
	@InitBinder
	public void initBinder(WebDataBinder binder, HttpServletRequest request) { // Register static property editors.
		binder.registerCustomEditor(java.util.Calendar.class, new org.skyway.spring.util.databinding.CustomCalendarEditor());
		binder.registerCustomEditor(byte[].class, new org.springframework.web.multipart.support.ByteArrayMultipartFileEditor());
		binder.registerCustomEditor(boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(false));
		binder.registerCustomEditor(Boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(true));
		binder.registerCustomEditor(java.math.BigDecimal.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(java.math.BigDecimal.class, true));
		binder.registerCustomEditor(Integer.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Integer.class, true));
		binder.registerCustomEditor(java.util.Date.class, new org.skyway.spring.util.databinding.CustomDateEditor());
		binder.registerCustomEditor(String.class, new org.skyway.spring.util.databinding.StringEditor());
		binder.registerCustomEditor(Long.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Long.class, true));
		binder.registerCustomEditor(Double.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Double.class, true));
	}

	/**
	* Get CureTaskMethod entity by CureTaskMedicine
	* 
	*/
	@RequestMapping(value = "/CureTaskMedicine/{curetaskmedicine_id}/cureTaskMethod", method = RequestMethod.GET)
	@ResponseBody
	public CureTaskMethod getCureTaskMedicineCureTaskMethod(@PathVariable Integer curetaskmedicine_id) {
		return cureTaskMedicineDAO.findCureTaskMedicineByPrimaryKey(curetaskmedicine_id).getCureTaskMethod();
	}

	/**
	* Show all CureTaskMedicine entities
	* 
	*/
	@RequestMapping(value = "/CureTaskMedicine", method = RequestMethod.GET)
	@ResponseBody
	public List<CureTaskMedicine> listCureTaskMedicines() {
		return new java.util.ArrayList<CureTaskMedicine>(cureTaskMedicineService.loadCureTaskMedicines());
	}

	/**
	* Create a new CureTaskMethod entity
	* 
	*/
	@RequestMapping(value = "/CureTaskMedicine/{curetaskmedicine_id}/cureTaskMethod", method = RequestMethod.POST)
	@ResponseBody
	public CureTaskMethod newCureTaskMedicineCureTaskMethod(@PathVariable Integer curetaskmedicine_id, @RequestBody CureTaskMethod curetaskmethod) {
		cureTaskMedicineService.saveCureTaskMedicineCureTaskMethod(curetaskmedicine_id, curetaskmethod);
		return cureTaskMethodDAO.findCureTaskMethodByPrimaryKey(curetaskmethod.getId());
	}

	/**
	* Save an existing CureTaskMedicine entity
	* 
	*/
	@RequestMapping(value = "/CureTaskMedicine", method = RequestMethod.PUT)
	@ResponseBody
	public CureTaskMedicine saveCureTaskMedicine(@RequestBody CureTaskMedicine curetaskmedicine) {
		cureTaskMedicineService.saveCureTaskMedicine(curetaskmedicine);
		return cureTaskMedicineDAO.findCureTaskMedicineByPrimaryKey(curetaskmedicine.getId());
	}

	/**
	* Get Medicine entity by CureTaskMedicine
	* 
	*/
	@RequestMapping(value = "/CureTaskMedicine/{curetaskmedicine_id}/medicine", method = RequestMethod.GET)
	@ResponseBody
	public Medicine getCureTaskMedicineMedicine(@PathVariable Integer curetaskmedicine_id) {
		return cureTaskMedicineDAO.findCureTaskMedicineByPrimaryKey(curetaskmedicine_id).getMedicine();
	}

	/**
	* Delete an existing Medicine entity
	* 
	*/
	@RequestMapping(value = "/CureTaskMedicine/{curetaskmedicine_id}/medicine/{medicine_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteCureTaskMedicineMedicine(@PathVariable Integer curetaskmedicine_id, @PathVariable Integer related_medicine_id) {
		cureTaskMedicineService.deleteCureTaskMedicineMedicine(curetaskmedicine_id, related_medicine_id);
	}

	/**
	* Create a new CureTaskMedicine entity
	* 
	*/
	@RequestMapping(value = "/CureTaskMedicine", method = RequestMethod.POST)
	@ResponseBody
	public CureTaskMedicine newCureTaskMedicine(@RequestBody CureTaskMedicine curetaskmedicine) {
		cureTaskMedicineService.saveCureTaskMedicine(curetaskmedicine);
		return cureTaskMedicineDAO.findCureTaskMedicineByPrimaryKey(curetaskmedicine.getId());
	}

	/**
	* Delete an existing CureTaskMedicine entity
	* 
	*/
	@RequestMapping(value = "/CureTaskMedicine/{curetaskmedicine_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteCureTaskMedicine(@PathVariable Integer curetaskmedicine_id) {
		CureTaskMedicine curetaskmedicine = cureTaskMedicineDAO.findCureTaskMedicineByPrimaryKey(curetaskmedicine_id);
		cureTaskMedicineService.deleteCureTaskMedicine(curetaskmedicine);
	}

	/**
	* Create a new Unit entity
	* 
	*/
	@RequestMapping(value = "/CureTaskMedicine/{curetaskmedicine_id}/unit", method = RequestMethod.POST)
	@ResponseBody
	public Unit newCureTaskMedicineUnit(@PathVariable Integer curetaskmedicine_id, @RequestBody Unit unit) {
		cureTaskMedicineService.saveCureTaskMedicineUnit(curetaskmedicine_id, unit);
		return unitDAO.findUnitByPrimaryKey(unit.getId());
	}

	/**
	* View an existing Medicine entity
	* 
	*/
	@RequestMapping(value = "/CureTaskMedicine/{curetaskmedicine_id}/medicine/{medicine_id}", method = RequestMethod.GET)
	@ResponseBody
	public Medicine loadCureTaskMedicineMedicine(@PathVariable Integer curetaskmedicine_id, @PathVariable Integer related_medicine_id) {
		Medicine medicine = medicineDAO.findMedicineByPrimaryKey(related_medicine_id, -1, -1);

		return medicine;
	}

	/**
	* Select an existing CureTaskMedicine entity
	* 
	*/
	@RequestMapping(value = "/CureTaskMedicine/{curetaskmedicine_id}", method = RequestMethod.GET)
	@ResponseBody
	public CureTaskMedicine loadCureTaskMedicine(@PathVariable Integer curetaskmedicine_id) {
		return cureTaskMedicineDAO.findCureTaskMedicineByPrimaryKey(curetaskmedicine_id);
	}

	/**
	* Save an existing Unit entity
	* 
	*/
	@RequestMapping(value = "/CureTaskMedicine/{curetaskmedicine_id}/unit", method = RequestMethod.PUT)
	@ResponseBody
	public Unit saveCureTaskMedicineUnit(@PathVariable Integer curetaskmedicine_id, @RequestBody Unit unit) {
		cureTaskMedicineService.saveCureTaskMedicineUnit(curetaskmedicine_id, unit);
		return unitDAO.findUnitByPrimaryKey(unit.getId());
	}

	/**
	* Get Unit entity by CureTaskMedicine
	* 
	*/
	@RequestMapping(value = "/CureTaskMedicine/{curetaskmedicine_id}/unit", method = RequestMethod.GET)
	@ResponseBody
	public Unit getCureTaskMedicineUnit(@PathVariable Integer curetaskmedicine_id) {
		return cureTaskMedicineDAO.findCureTaskMedicineByPrimaryKey(curetaskmedicine_id).getUnit();
	}

	/**
	* Delete an existing Unit entity
	* 
	*/
	@RequestMapping(value = "/CureTaskMedicine/{curetaskmedicine_id}/unit/{unit_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteCureTaskMedicineUnit(@PathVariable Integer curetaskmedicine_id, @PathVariable Integer related_unit_id) {
		cureTaskMedicineService.deleteCureTaskMedicineUnit(curetaskmedicine_id, related_unit_id);
	}

	/**
	* Delete an existing CureTaskMethod entity
	* 
	*/
	@RequestMapping(value = "/CureTaskMedicine/{curetaskmedicine_id}/cureTaskMethod/{curetaskmethod_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteCureTaskMedicineCureTaskMethod(@PathVariable Integer curetaskmedicine_id, @PathVariable Integer related_curetaskmethod_id) {
		cureTaskMedicineService.deleteCureTaskMedicineCureTaskMethod(curetaskmedicine_id, related_curetaskmethod_id);
	}
}